// custom-tab-bar/index.js
const event = require('../../../utils/event.js')
const common = require('../../../common/index')

var app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    selected: {
      type: Number,
      value: 0
    },
    tab2name: {
      type: String,
      value: '消息'
    },
    isShow: {
      type: Boolean,
      value: true,
    },
    isShowRedDot: {
      type: Boolean,
      value: false,
    },
    redMsg: {
      type: Number,
      value: 0
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    app,
    isRedDot: false,
    redMsg: 0,
    //  tab2name: '职位',
    //  isShow: true,
    // isShowRedDot: false
  },

  attached() {
    /*  this.setData({
       selected: app.globalData.selectedTab
     })
     console.log(this.data.selected,'------',app.globalData.selectedTab) */

    if (wx.getStorageSync(common.CC_USER_TYPE) == 4) {
      this.setData({
        isShow: false
      })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset.type
      let url = e.currentTarget.dataset.url
      let index = 0;
      switch (data) {
        case 'index':
          index = 0
          break;
        case 'position':
          index = 1
          if (this.data.tab2name == '人才') {
            url = '/package1/pages/views/talenTab/talenTab'
          }
          break
        case 'message':
          index = 2
          break;
        case 'user':
          index = 3
          break;
        default:
          break;
      }
      //这个方法如果调用，会导致tab bar闪动一下，这个是个bug
      /*   this.setData({
          selected: index
        }) */
      //  wx.switchTab({ url })
      wx.reLaunch({
        url
      })
      event.emit(common.CC_SWITCH_TAB, {
        index: index
      })
    }

  }
})